﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Finance.Querys;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Finance.Finances
{
    [RemoteService]
    [Route("api/v1/journals")]
    public class JournalController : BaseController
    {
        private IJournalAppService _appService;
        public JournalController(IJournalAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        public async Task<PagedResultDto<JournalDto>> GetPageAsync(JournalPageQuery query)
        {
            var result = await _appService.FindAsync(query);

            return result;
        }

        [HttpGet]
        [Route("{id}")]
        public async Task<JournalDto> GetAsync(Guid id)
        {
            var result = await _appService.GetAsync(id);

            return result;
        }

        [HttpPost]
        public async Task<JournalDto> CreateAsync(JournalCreateDto journal)
        {
            var result = await _appService.CreateAsync(journal);

            return result;
        }

  
        [HttpPut]
        public async Task<JournalDto> UpdateAsync(JournalUpdateDto journal)
        {
            var result = await _appService.UpdateAsync(journal);

            return result;
        }

        [HttpPut]
        [Route("{id}/approve")]
        public async Task<JournalDto> ApproveAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        [HttpPut]
        [Route("{id}/unapprove")]
        public async Task<JournalDto> UnapproveAsync(Guid id)
        {
            throw new NotImplementedException();
        }


        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }

        [HttpGet]
        [Route("nextnumber")]
        public async Task<string> NextNumberAsync(Guid numberPrefixId , int period)
        {
            var result = await _appService.GetNextNumberAsync(numberPrefixId , period);

            return result;
        }

        [HttpGet]
        [Route("count")]
        public async Task<int> GetCountAsync(int? period)
        {
            var result = await _appService.GetCountAsync(period);

            return result;
        }
    }
}
